package com.corpdata.app.customer.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.corpdata.app.contract.service.ContractInfoService;
import com.corpdata.app.customer.dao.CustomerTeamMapper;
import com.corpdata.app.customer.entity.CustomerTeam;
import com.corpdata.app.customer.service.CustomerIntegralService;
import com.corpdata.app.customer.service.CustomerStaffService;
import com.corpdata.app.customer.service.CustomerTeamService;
import com.corpdata.app.project.service.ProjectStationService;
import com.corpdata.common.result.Result;
import com.corpdata.common.utils.CorpdataUtil;
import com.corpdata.core.base.AbstractBaseService;
import com.corpdata.system.dic.entity.SysDataDic;

/**
 * 团队表
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-13 16:46:46
 */
@Service
@Transactional
public class CustomerTeamServiceImpl extends AbstractBaseService<CustomerTeam> implements CustomerTeamService {
	
	@Autowired
	private CustomerTeamMapper customerTeamMapper;
	
	@Autowired
	private CustomerStaffService customerStaffService;
	
	@Autowired
	private ContractInfoService contractInfoService;
	
	@Autowired
	private CustomerIntegralService customerIntegralService;
	
	
	@Autowired
	private ProjectStationService projectStationService;
	public Result insert(CustomerTeam record,String dicIndustryId,String dicStageId){
		String id=CorpdataUtil.getUUID();
		record.setId(id);
		SysDataDic IndustrydataDic=new SysDataDic();
		IndustrydataDic.setId(dicIndustryId);
		record.setDicIndustry(IndustrydataDic);
		SysDataDic StagedataDic=new SysDataDic();
		StagedataDic.setId(dicStageId);
		record.setDicStage(StagedataDic);
		record.setDeliverDetails(false);
		record.setCardKnowledge(false);
		record.setCardAuthorization(false);
		record.setLesseeState(0);
		record.setSimpleNamePinyin(CorpdataUtil.ToFirstChar(record.getSimpleName().substring(0,1)));
		return super.save(record);
	}
	
	/**
	 * 获取下拉json数据
	 * @return
	 */
	public String selectAllByCombox(String id){
		String json = CorpdataUtil.getComboxJson(customerTeamMapper.selectAllByCombox(id));
		return json;
	}

	@Override
	public List<CustomerTeam> selectByPid(String projectId) {
		return customerTeamMapper.selectByPid(projectId);
	}
	
	public String statistics(String id){
		String json = "";
		int staff=customerStaffService.selectAll(id);
		int contractDay=contractInfoService.getDaoQiDays(id);
		int projectStation=projectStationService.selectAll(id);
		int existingBalance=customerIntegralService.findById(id).getExistingBalance();
		json="{\"staff\":\""+staff+"\",\"contractDay\":\""+contractDay+"\",\"projectStation\":\""+projectStation+"\",\"existingBalance\":\""+existingBalance+"\"}";
		return json;
	}
}
